package com.demo.designmode.template.case1;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * 获取数据库连接工厂类
 * @author jiaxXM
 * @date 2024/9/3
 */
public class ConnectFactory {

    public static Connection getConnection() throws Exception{
        GlobalProperties properties = SpringContextUtil
                .getBean("globalProperties", GlobalProperties.class);
        //加载数据驱动
        Class.forName(properties.getDriverClass());
        //获取数据库连接，返回数据库连接对象
        return DriverManager.getConnection(properties.getUrl(),
                properties.getUsername(), properties.getPassword());
    }
}
